package br.com.util ;

import org.apache.log4j.Logger ;
import org.quartz.CronScheduleBuilder ;
import org.quartz.JobBuilder ;
import org.quartz.JobDetail ;
import org.quartz.Scheduler ;
import org.quartz.SchedulerFactory ;
import org.quartz.Trigger ;
import org.quartz.TriggerBuilder ;
import org.quartz.impl.StdSchedulerFactory ;


public class JobLeituraNotaFiscal
{
    private static Logger logger = Logger.getLogger( JobLeituraNotaFiscal.class ) ;
    
    
    private JobLeituraNotaFiscal( )
    {
    }

    public static void iniciarJob( )
    {
        try
        {
            SchedulerFactory schedFact = new StdSchedulerFactory( ) ;
            Scheduler        sched     = schedFact.getScheduler ( ) ;
            
            sched.start( ) ;
            
            JobDetail job     = JobBuilder.newJob( Robo.class ).withIdentity( "robo", "Leitura" ).build( ) ;
            Trigger   trigger = TriggerBuilder.newTrigger( ).withIdentity( "gatilho", "Leitura" ).withSchedule( CronScheduleBuilder.cronSchedule( "0/180 * * * * ?" ) ).build( ) ;
            
            sched.scheduleJob( job, trigger ) ;
        }
        catch( Exception e )
        {
            logger.error( e ) ;
        }
    }
}
